from pml import Objects

class PMListObject(Objects.object.typeobject):
    def __init__(self, value: list = []):
        super().__init__('list')
        self.value = value
        self.len = len(value)
        self.iter = -1
    def __repr__(self):
        return self.value.__repr__()

    def __eq__(self, other):
        if isinstance(other, list):
            return self.value == other
        else:
            return self.value == other.obj.value

    def __iter__(self):
        self.iter = -1
        return self
    def __next__(self):
        self.iter += 1
        if self.iter == self.len:
            raise StopIteration
        return self.value[self.iter]
    def __hash__(self):
        return self.value.__hash__()
    def __getitem__(self, item):
        return self.value[item]
    def __len__(self):
        return self.len

    def getObject(self):
        self.methods['__init__'] = self.tp_init,
        self.methods['__print__'] = self.tp_print,

        self.methods['__string__'] = self.tp_string

        return self

    def last(self):
        self.iter -= 1
        return self.value[self.iter]

    @staticmethod
    def tp_init(frame, this, value, position):
        pass

    @staticmethod
    def tp_print(frame, this, position):
        return this.tp_string(frame, this, position=position)

    @staticmethod
    def tp_string(frame, this, position):
        pass

